package com.cmy.scheduleLite.bean;

import lombok.Getter;
import org.springframework.lang.Nullable;
import org.springframework.scheduling.config.Task;

import java.util.concurrent.ScheduledFuture;

/**
 * @author : Cmy
 * @date : 2025-04-09 9:45
 */
public class ScheduledTask {

    @Getter
    private final Task task;
    @Nullable
    public volatile ScheduledFuture<?> future;

    public ScheduledTask(Task task) {
        this.task = task;
    }

    public void cancel() {
        this.cancel(true);
    }

    public void cancel(boolean mayInterruptIfRunning) {
        ScheduledFuture<?> future = this.future;
        if (future != null) {
            future.cancel(mayInterruptIfRunning);
        }

    }

    public String toString() {
        return this.task.toString();
    }

}

    